<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:67:"F:\yxl\tp5.com\public/../application/admin\view\auth\group_add.html";i:1560772044;}*/ ?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .select1{
            width:300px;
            height: 30px;
        }
    </style>
</head>
<body>
<div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">
        <form class="layui-form" action="<?php echo url('admin/group/group_add_do'); ?>" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label">用户组名</label>
                <div class="layui-input-block">
                    <input type="text" name="title" required  lay-verify="required" placeholder="请输入组名" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">状态码</label>
                <div class="layui-input-block">
                    <input type="text" name="status" required  lay-verify="required" placeholder="请输入状态" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                    权限
                </fieldset>

                <div id="test7" class="demo-tree" ></div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" id="rule" name="rules" />
                    <button class="layui-btn" id="text1" >立即提交</button>
                </div>
            </div>
        </form>

    </div>
</div>

<div class="layui-footer">
    <!-- 底部固定区域 -->
    © layui.com - 底部固定区域
</div>
</body>
</html>
<script src="/static/layui/layui.js"></script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#test11'
        });
    });

</script>
<script>
    //Demo

    layui.use(['form','jquery','layedit','tree'], function() {
        var form = layui.form;
        var jquery=layui.jquery
        tree=layui.tree;
        var bool = [];
        var rules = [];
        //开启复选框
        jquery(document).ready(function(){
            jquery.post('/admin/auth/group_add',{p_id:0},function(res){
                console.log(res);
                var arr=new Array();
                for(var i=0;i<res.length;i++){
                    arr.push(res[i]);
                }
                //p alert(11);
                console.log(arr);
                console.log(arr.elem)
                tree.render({
                    elem: '#test7'
                    ,data:arr
                    ,id:'demoId'
                    ,showCheckbox: true
                    ,oncheck: function(obj){
                        //先判断当前选中节点是否是  选中状态
                        if(obj.checked == true){
                            //再判断当前选中节点是否有子级
                            if(obj.data.children){
                                //再判断rules变量数组中是否有重复数据
                                if(jquery.inArray(obj.data,rules) == -1){
                                    //如果都通过，将当前节点数据，压到rules数组变量中
                                    rules.push(obj.data);
                                }
                                //如果当前节点没有子级的话
                            }else{
                                //循环一下当前已经存储在入了是变量中的数据
                                jquery.each(rules,function(index,p){
                                    //只循环有子级的
                                    if(p.children){
                                        //如果当前节点数据不存在于循环出子级数组内
                                        if(jquery.inArray(obj.data,p.children) == -1){
                                            bool[index] = true;
                                            //rules.push(obj.data);
                                        }else{
                                            bool[index] = false;
                                        }
                                    }
                                })
                                var i = 0;
                                var res = 0;
                                for(i=0;i<=boll.length;i++){
                                    if(boll[i] == true){
                                        res++;
                                    }
                                }
                                if(res >=1 ){
                                    rules.push(obj.data);
                                }
                            }
                            //如果当前点击的节点是false
                        }else{
                            //如果当前点击的节点有子级
                            if(obj.data.children){
                                jquery.each(rules,function(index,p){
                                    if(p == obj.data){
                                        rules.splice(index, 1);
                                    }
                                });

                            }else{
                                jquery.each(rules,function(index,p){
                                    //只循环有子级的
                                    if(p.children){
                                        //如果当前节点数据不存在于循环出子级数组内
                                        jquery.each(p.children,function(k,v) {
                                            if(v == obj.data){
                                                console.log(v);
                                                p.children.splice(k, 1);
                                            }
                                        });
                                    }else{
                                        if(p == obj.data){
                                            p.splice(index, 1);
                                        }
                                    }
                                })
                            }
                        }
                        console.log(rules);
                        var str = JSON.stringify(rules);
                        jquery('#rule').val(str);
                        //console.log(jquery('#rule').val());
                    }
                });
            });
        })
    });
</script>